<?php

/**
 * QueryHandler is handling query and choose right DatabaseConnection
 * @package Core
 * @subpackage Database
 * @author kovacsricsi
 */
class QueryHandler implements IQueryHandler {
    /**
     * Database type
     * @access protected
     * @static
     * @var string
     */
    protected static $_dbType = null;

    /**
     * Set database type
     * @access public
     * @static
     * @param string $dbType
     * @return void
     */
    public static function setDbType($dbType)
    {
        self::$_dbType = (string)$dbType;
    }

	/**
	 * Returns all row from database.
	 * @access public
	 * @static
	 * @param string $query
	 * @param array $prepare
	 * @param string $name
     * @throws DatabaseErrorException
	 * @return array
	 */
	public static function getAll($query = "", $prepare = null, $name = "default")
    {
        if (self::$_dbType == null) {
            self::setDbType(DB_TYPE);
        }

        if (self::$_dbType == "MySQL") {
            return MySQLQueryHandler::getAll($query, $prepare, $name);
        } else {
            throw new DatabaseErrorException("Database not set!");
        }
    }

	/**
	 * Returns one row from database.
	 * @access public
	 * @static
	 * @param string $query
	 * @param array $prepare
	 * @param string $name
     * @throws DatabaseErrorException
	 * @return array
	 */
	public static function getOne($query = "", $prepare = null, $name = "default")
    {
        if (self::$_dbType == null) {
            self::setDbType(DB_TYPE);
        }

        if (self::$_dbType == "MySQL") {
            return MySQLQueryHandler::getOne($query, $prepare, $name);
        } else {
            throw new DatabaseErrorException("Database not set!");
        }
    }

	/**
	 * Execute query.
	 * @access public
	 * @static
	 * @param string $query
	 * @param array $prepare
	 * @param string $name
     * @throws DatabaseErrorException
	 * @return void
	 */
	public static function execute($query = "", $prepare = null, $name = "default")
    {
        if (self::$_dbType == null) {
            self::setDbType(DB_TYPE);
        }

        if (self::$_dbType == "MySQL") {
            MySQLQueryHandler::execute($query, $prepare, $name);
        } else {
            throw new DatabaseErrorException("Database not set!");
        }
    }
}

?>
